<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

require_once 'util/TipoUsuarioEnum.php';

class Plugin_ChecagemDeAcesso extends Zend_Controller_Plugin_Abstract
{
    private $_acl  = null;
    
    private $_auth = null;

    public function  __construct (Zend_Acl $acl, Zend_Auth $auth)
    {
        $this->_acl  = $acl;

        $this->_auth = $auth;
    }

    public function preDispatch (Zend_Controller_Request_Abstract $request)
    {
        $resource = $request->getControllerName ();
        
        $action   = $request->getActionName ();

        $identity = $this->_auth->getStorage ()->read ();

   //     if (isset ($identity))
      
        $role     = $this->_acl->getRoleName ($identity->id_tipo_usuario);
        
     //   else

       //     $role = $this->getRoleName (0);

        if (!$this->_acl->isAllowed ($role, $resource, $action))
        {
            
            $request->setControllerName('index')
                    ->setActionName('noscript');
        }

        
    }
    

   

    


}
 

